<?php
//后台首页模块
class IndexAction extends CommonAction {
	// 框架首页
	public function index() {
		if (isset ( $_SESSION [C ( 'USER_AUTH_KEY' )] )) {
			//显示菜单项
			$menu = array ();
			//读取数据库模块列表生成菜单项
			$node = M ( "Node" );
			$id = $node->getField ( "id" );
			$where ['level'] = 2;
			$where ['status'] = 1;
			$where ['pid'] = $id;
			$list = $node->where ( $where )->field ( 'id,name,group_id,title' )->order ( 'sort asc' )->select ();
			$accessList = $_SESSION ['_ACCESS_LIST'];
			/**
			 * 得到现有的后台分组的数据
			 */
			$group = M ( "Group" );
			$wh ['status'] = 1;
			$wh ['show'] = 0;
			$list_group = $group->where ( $wh )->field ( 'id,name,title' )->order ( 'sort asc' )->select ();
			$temp = array ();
		    foreach ($list_group as $k => $v){	
		    	$temp="";
				foreach ( $list as $key => $module ) {
					if (isset ( $accessList [strtoupper ( APP_NAME )][strtoupper ( $module ['name'] )] ) || $_SESSION ['administrator']) {
						//设置模块访问权限
						$module ['access'] = 1;
						//划分组别
						if($module ['group_id']==$v['id']){
						   $temp[]=$module; 
						}
					}
				}
				if (isset ( $accessList [strtoupper ( APP_NAME )][$v['id']] ) || $_SESSION ['administrator']){
				$menu [$k]['menu']=$temp; 
		        $menu [$k]['group_title']=$v['title'];   
				}
		    }			
			if (! empty ( $_GET ['tag'] )) {
				$this->assign ( 'menuTag', $_GET ['tag'] );
			}
			$this->assign ( 'menu', $menu );
		}
		C ( 'SHOW_RUN_TIME', false ); // 运行时间显示
		C ( 'SHOW_PAGE_TRACE', false );
		unset($accessList);
		$this->display ();
			
	}
	
//清除所有的缓存
	public function clearcache() {
		$bl=$this->xDelete(C('RUNTIME_PATH'));

		if ($bl!==false) {
			$this->assign ( "jumpUrl", $this->getReturnUrl () );
			$this->success ( '缓存清除成功' );
		} else {
			$this->error  (  '缓存清除失败！' );
		}
	}
}